package com.ruoyi.finance.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.finance.domain.VoucherWord;
import com.ruoyi.finance.service.IVoucherWordService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 凭证字管理Controller
 *
 * @author ruoyi
 * @date 2025-03-03
 */
@RestController
@RequestMapping("/finance/word")
public class VoucherWordController extends BaseController
{
    @Autowired
    private IVoucherWordService voucherWordService;

    /**
     * 查询凭证字管理列表
     */
    @PreAuthorize("@ss.hasPermi('finance:word:list')")
    @GetMapping("/list")
    public TableDataInfo list(VoucherWord voucherWord)
    {
        startPage();
        List<VoucherWord> list = voucherWordService.selectVoucherWordList(voucherWord);
        return getDataTable(list);
    }

    /**
     * 导出凭证字管理列表
     */
    @PreAuthorize("@ss.hasPermi('finance:word:export')")
    @Log(title = "凭证字管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, VoucherWord voucherWord)
    {
        List<VoucherWord> list = voucherWordService.selectVoucherWordList(voucherWord);
        ExcelUtil<VoucherWord> util = new ExcelUtil<VoucherWord>(VoucherWord.class);
        util.exportExcel(response, list, "凭证字管理数据");
    }

    /**
     * 获取凭证字管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('finance:word:query')")
    @GetMapping(value = "/{wordId}")
    public AjaxResult getInfo(@PathVariable("wordId") Long wordId)
    {
        return success(voucherWordService.selectVoucherWordByWordId(wordId));
    }

    /**
     * 新增凭证字管理
     */
    @PreAuthorize("@ss.hasPermi('finance:word:add')")
    @Log(title = "凭证字管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody VoucherWord voucherWord)
    {
        return toAjax(voucherWordService.insertVoucherWord(voucherWord));
    }

    /**
     * 修改凭证字管理
     */
    @PreAuthorize("@ss.hasPermi('finance:word:edit')")
    @Log(title = "凭证字管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody VoucherWord voucherWord)
    {
        return toAjax(voucherWordService.updateVoucherWord(voucherWord));
    }

    /**
     * 删除凭证字管理
     */
    @PreAuthorize("@ss.hasPermi('finance:word:remove')")
    @Log(title = "凭证字管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{wordIds}")
    public AjaxResult remove(@PathVariable Long wordIds)
    {
        return toAjax(voucherWordService.deleteVoucherWordByWordId(wordIds));
    }
}
